home *** CD-ROM | disk | FTP | other *** search
- Path: news.tu-chemnitz.de!news
- From: hfst@hrz.tu-chemnitz.de (Hans Steffani)
- Newsgroups: comp.lang.c
- Subject: Re: A weird thing about printf()
- Date: 10 Apr 96 10:46:09 GMT
- Organization: University of Technology Chemnitz, FRG
- Message-ID: <4kg3k8$ncn@narses.hrz.tu-chemnitz.de>
- References: <4kflr2$5if@dewey.csun.edu>
- NNTP-Posting-Host: sisyphus.hrz.tu-chemnitz.de
-
- kc44097@csun.edu (chen) writes:
-
- >#include <stdio.h>
-
- >int answer;
- >main()
- >{
- > answer=2+2;
- > printf("The answer is %d\n");
- > return 0;
- >}
-
- > In printf(),I lost "answer" in the end,but it works,and give me the
- >result 0.I wonder how the compiler handle this condition.Also,is this
- >allow by C?(by this, I mean is this a leagal usage in language itself,
- >or just a mistake cause by the compiler?)
-
- The printf() does not know that there is one argument missing.
- Therefore it handles in its normal way. Assuming stack passing
- it takes some random value from the stack as its 2nd argument.
-
- h.f.s.
- --
- Hans Friedrich Steffani
- Institut fuer Elektrische Maschinen und Antriebe
- TU Chemnitz-Zwickau
- e-mail: hans.steffani@e-technik.tu-chemnitz.de
-